package com.gufe.controller.user.community;

import com.gufe.dto.communitydto.PostDTO;
import com.gufe.result.Result;
import com.gufe.service.user.community.PostService;
import com.gufe.vo.communityvo.PostVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 社区模块帖子相关接口
@RestController
@RequestMapping("/api/user/community")
@Slf4j
public class PostController {

    @Autowired
    private PostService postService;

    // 获取帖子数据
    @GetMapping("/posts")
    public Result getPosts() {
        log.info("获取帖子数据...");
        List<PostVO> posts = postService.getPosts();
        return Result.success(posts);
    }


    // 根据ID获取帖子详情信息
    @GetMapping("/post/{id}")
    public Result getPostById(@PathVariable Integer id) {
        log.info("获取帖子id：{}详细信息",id);
        PostVO post = postService.getPostById(id);
        return Result.success(post);
    }

    // 添加帖子
    @PostMapping("/post")
    public Result savePost(@RequestBody PostDTO postDTO) {
        log.info("新增帖子...");
        postService.savePost(postDTO);
        return Result.success();
    }
}

